﻿package
{

    import flash.net.NetConnection;
    import flash.net.ObjectEncoding;
    import flash.events.NetStatusEvent;
	import flash.net.Responder;
    import flash.display.Sprite;
	import flash.events.SyncEvent;
	import flash.net.SharedObject;
	import flash.events.MouseEvent;
	import flash.events.Event;
	 import flash.events.KeyboardEvent;
	



    public class Main extends Sprite
    {

			private var connection:NetConnection;
			private var rso:SharedObject;
			private var responder:Responder;
			
			
			public function Main() : void {
				// setup connection code
				connection = new NetConnection();
				connection.addEventListener( NetStatusEvent.NET_STATUS , netStatus ); //ben ekledim
				connection.connect("rtmp://localhost/cizanlat");
				connection.client = this;
				
				// create the remote SharedObject
				rso = SharedObject.getRemote("coordinates", connection.uri);
				rso.addEventListener(SyncEvent.SYNC, onSync);
				rso.connect(connection);
				
				// instantiate the embedded asset
				
				
	
				addEventListener(Event.ENTER_FRAME,Main);

			}
			
			
			private function onSync(event:SyncEvent) : void {
				//trace("event: " + event);
				
				for(var i:Object in event.changeList) {
					var changeObj:Object = event.changeList[i];
					
					switch(changeObj.code) {
						case "success":
							break;
						
						case "change":
							var coordinates = this.rso.data[changeObj.name];
							for(var k=1;k<=2;k++)
							{
								if(coordinates.id!=myid){
									player[coordinates.id].x=coordinates.x;
									player[coordinates.id].y=coordinates.y;
									if(coordinates.sutvur){player[coordinates.id].gotoAndStop(2);}else{player[coordinates.id].gotoAndStop(1);}
								}
							}
							break;
					}
					
				}
				
			}
			

var obj:Object = {x:100};
	rso.setProperty("coordinates", obj);
	}
 }

 
			
			 private function netStatus ( event:NetStatusEvent ):void
        {

            trace( event.info.code );

            if ( event.info.code == "NetConnection.Connect.Rejected" )
            {

                // trace reject message

                trace( event.info.application );

            }
			
			if ( event.info.code == "NetConnection.Connect.Success" )
            {
              trace("olduuu");
            }

        }
    }

}